package com.hsd.znsh.controller.pc;

import com.hsd.znsh.entity.Monitor;
import com.hsd.znsh.entity.SensorGroup;
import com.hsd.znsh.pojo.output.MonitorVO;
import com.hsd.znsh.pojo.output.ResultVO;
import com.hsd.znsh.properties.SecurityProperties;
import com.hsd.znsh.service.MonitorService;
import com.hsd.znsh.service.UserService;
import com.hsd.znsh.utils.ResultVOUtil;
import com.hsd.znsh.utils.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/*
 * @auther: wangjiacai
 *
 * @create: 2018-04-27 10:18:15
 */
@RestController
@RequestMapping("/pc/monitor")
public class PCMonitorController {

    @Autowired
    private MonitorService monitorService;

    @GetMapping("/getQjMonitorList")
    public ResultVO getQjMonitorList(){
        List<Monitor> list=monitorService.getQjMonitorList();
        return ResultVOUtil.success(list);
    }

    @GetMapping("/getUserQjMonitorList")
    public ResultVO getUserQjMonitorList(){
        List<Monitor> list;
        if(SecurityUtil.hasRole("ROLE_PC_MANAGER")){
            list=monitorService.getQjMonitorList();
        }else{
            list=monitorService.getUserQjMonitorList(SecurityUtil.getUserId());
        }
        return ResultVOUtil.success(list);
    }

    @GetMapping("/getUjMonitorList")
    public ResultVO getUjMonitorList(){
        List<Monitor> list=monitorService.getUjMonitorList();
        return ResultVOUtil.success(list);
    }

    @GetMapping("/getUserUjMonitorList")
    public ResultVO getUserUjMonitorList(){
        List<Monitor> list;
        if(SecurityUtil.hasRole("ROLE_PC_MANAGER")){
            list=monitorService.getUjMonitorList();
        }else{
            list=monitorService.getUserUjMonitorList(SecurityUtil.getUserId());
        }
        return ResultVOUtil.success(list);
    }

    @GetMapping("/generalUserAddress")
    public ResultVO generalUserAddress(Integer id, HttpServletRequest request){
        Map map=monitorService.generalUserAddress(id,request);
        return ResultVOUtil.success(map);
    }

    @GetMapping("/vipOrManagerAddress")
    public ResultVO vipOrManagerAddress(Integer id){
        Map map=monitorService.vipOrManagerAddress(id);
        return ResultVOUtil.success(map);
    }

    @GetMapping("/getMonitorType")
    public ResultVO getMonitorType(Integer id){
        MonitorVO monitorVO=monitorService.getMonitorInfo(id);
        return ResultVOUtil.success(monitorVO.getMonitorTypeName());
    }

}
